package com.czk.netty.netty.tcp.client;

import com.czk.netty.netty.tcp.protocaltcp.protocol.MessageProtocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.nio.charset.Charset;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/1/24 16:00
 */
public class MyClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
    private int count;


    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {


    }
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception {
        // 读取数据
        byte[] bytes=new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(bytes);
        String message=new String(bytes,Charset.forName("utf-8"));
        System.out.println("接收的数据时message="+message);
        System.out.println("客户端接收的次数是"+(++this.count));
    }
}
